package gmu.swe.project.peer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;

/**
 * A representation of a Peer (client) from the Trackers (Server) perspective.  
 * Trackers will track the IP address of the Peer and the files that Peer is sharing.  
 * @author Christina
 *
 */
public class PeerInfo implements Serializable {
	private static final long serialVersionUID = 1L;
	
	/**
	 * A unique ID for this PeerInfo.
	 */
	private String id;
	
	/** A string representation of the IP address of the Peer.
	 *  Should take the form of a regular IP - 192.168.10.2
	 */
	private String ipAddress;
	
	/** An Integer representation of the port of this Peer.
	 * 
	 */
	private Integer port;
	
	/** An arraylist of files that the client has for sharing.  An arraylist is used b/c it's impossible to 
	 * tell how large this list needs to be; it can be constantly added to or removed from.
	 */
	private ArrayList files;
	
	/** The current workload of the Peer; determined by the server upon query and returned to other
	 * Peers for use in determining which Peer to down load from.
	 */
	private Integer workload;
	
	/** Timestamp used to determine when a keep alive message was sent to tracker
	 * 
	 */
	private Date timestamp;
	
	/**
	 * Create a new PeerInfo; initializing properties to an empty state
	 */
	public PeerInfo() {
		this.id = UUID.randomUUID().toString();
		this.ipAddress = "";
		this.files = new ArrayList<String>();
		this.workload = 0;
	}
	
	/**
	 * Add a file to the list of files.
	 * @param fileName
	 */
	public void addFile(String fileName) {
		//enforce uniqueness - allows the search to stop once it finds the first instance.
		if(!this.files.contains(fileName)) {
			this.files.add(fileName);
		}
	}
	/**
	 * Remove a file from the list of files.
	 * @param fileName
	 */
	public void removeFile(String fileName) {
		this.files.remove(fileName);
	}
	
	/** Accessors **/
	public String getIpAddress() {
		return ipAddress;
	}
	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}
	public ArrayList<String> getFiles() {
		return files;
	}
	public void setFiles(ArrayList<String> files) {
		this.files = files;
	}
	public Integer getWorkload() {
		return workload;
	}
	public void setWorkload(Integer workload) {
		this.workload = workload;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public Integer getPort() {
		return port;
	}
	public void setPort(Integer port) {
		this.port = port;
	}
	public Date getTimestamp() {
		return timestamp;
	}
	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}

}
